import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getx_learn/app/common/widgets/widgets.dart';

import '../controllers/get_utils_demo_controller.dart';

class GetUtilsDemoView extends GetView<GetUtilsDemoController> {
   GetUtilsDemoView({Key? key}) : super(key: key);

  var textFieldController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(context: context, title: "GetUtilsDemoView"),
      body: ListView(
        children: [
          Text("""
          GetUtils是getx为我们提供一些常用的工具类库，包括值是否为空、是否是数字、
          是否是视频、图片、音频、PPT、Word、APK、邮箱、手机号码、日期、MD5、SHA1等等。
          """),
          Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Padding(
                  padding: EdgeInsets.all(20),
                  child: TextField(
                    controller: textFieldController,
                  ),
                ),
                SizedBox(height: 10,),
                Padding(
                  padding: EdgeInsets.all(10),
                  child: ElevatedButton(
                    child: Text("判断是否是邮箱"),
                    onPressed: () async {
                      if (GetUtils.isEmail(textFieldController.text)) {
                        Get.snackbar("正确", "恭喜你, 完全正确", backgroundColor: Colors.greenAccent);
                      } else {
                        Get.snackbar(
                            "邮箱错误",
                            "请输入正确的邮箱",
                            backgroundColor: Colors.pink
                        );
                      }
                    },
                  ),
                ),
                Padding(
                  padding: EdgeInsets.all(10),
                  child: ElevatedButton(
                    child: Text("判断是否是手机号"),
                    onPressed: () async {
                      if (GetUtils.isPhoneNumber(textFieldController.text)) {

                        Get.snackbar("正确", "恭喜你, 完全正确", backgroundColor: Colors.greenAccent);
                      } else {
                        Get.snackbar(
                            "手机号错误",
                            "请输入正确的手机号",
                            backgroundColor: Colors.pink
                        );
                      }
                    },
                  ),
                ),
                Padding(
                  padding: EdgeInsets.all(10),
                  child: ElevatedButton(
                    child: Text("判断是否是IPv4"),
                    onPressed: () async {
                      if (GetUtils.isIPv4(textFieldController.text)) {

                        Get.snackbar("正确", "恭喜你, 完全正确", backgroundColor: Colors.greenAccent);
                      } else {
                        Get.snackbar(
                            "地址错误",
                            "请输入正确的IPv4地址",
                            backgroundColor: Colors.pink
                        );
                      }
                    },
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
